#lang rosetta-racket


(provide open-line
         automatically-closed-line
         closed-line
         closed-line-with-warning
         
         open-line-begin-c
         open-line-end-c
         open-line-cs
         
         automatically-closed-line-begin-c
         automatically-closed-line-end-c
         automatically-closed-line-cs
         
         closed-line-begin-c
         closed-line-end-c
         closed-line-cs
         
         closed-line-with-warning-begin-c
         closed-line-with-warning-end-c
         closed-line-with-warning-cs)


(define (open-line)
  (lift
   (thunk (displayln "Open line"))
   (line u0 ux uxyz)))

(define (automatically-closed-line)
  (lift
   (thunk (displayln "Automatically closed line"))
   (move-x 1 (line u0 ux uxyz u0))))

(define (closed-line)
  (lift
   (thunk (displayln "Closed line"))
   (move-x 2 (line-closed u0 ux uxyz))))

(define (closed-line-with-warning)
  (lift
   (thunk (displayln "Closed line with a warning"))
   (move-x 3 (line-closed u0 ux uxyz u0))))


(define (open-line-begin-c)
  (displayln "Open line begin coord")
  (let ((c (line-begin-c (line u0 ux uxyz))))
    (if (=c c u0)
        c
        (error 'open-line-begin-c))))

(define (open-line-end-c)
  (displayln "Open line end coord")
  (let ((c (line-end-c (line u0 ux uxyz))))
    (if (=c c uxyz)
        c
        (error 'open-line-end-c))))

(define (open-line-cs)
  (displayln "Open line coords")
  (let ((cs (line-cs (line u0 ux uxyz))))
    (if (andmap =c cs (list u0 ux uxyz))
        cs
        (error 'open-line-cs))))

(define (automatically-closed-line-begin-c)
  (displayln "Automatically closed line begin coord")
  (let ((c (line-begin-c (line u0 ux uxyz u0))))
    (if (=c c u0)
        c
        (error 'automatically-closed-line-begin-c))))

(define (automatically-closed-line-end-c)
  (displayln "Automatically closed line end coord")
  (let ((c (line-end-c (line u0 ux uxyz u0))))
    (if (=c c u0)
        c
        (error 'automatically-closed-line-end-c))))

(define (automatically-closed-line-cs)
  (displayln "Automatically closed line coords")
  (let ((cs (line-cs (line u0 ux uxyz u0))))
    (if (andmap =c cs (list u0 ux uxyz u0))
        cs
        (error 'automatically-closed-line-cs))))

(define (closed-line-begin-c)
  (displayln "Closed line begin coord")
  (let ((c (line-begin-c (line-closed u0 ux uxyz))))
    (if (=c c u0)
        c
        (error 'closed-line-begin-c))))

(define (closed-line-end-c)
  (displayln "Closed line end coord")
  (let ((c (line-end-c (line-closed u0 ux uxyz))))
    (if (=c c u0)
        c
        (error 'closed-line-end-c))))

(define (closed-line-cs)
  (displayln "Closed line coords")
  (let ((cs (line-cs (line-closed u0 ux uxyz))))
    (if (andmap =c cs (list u0 ux uxyz u0))
        cs
        (error 'closed-line-cs))))

(define (closed-line-with-warning-begin-c)
  (displayln "Closed line with a warning begin coord")
  (let ((c (line-begin-c (line-closed u0 ux uxyz u0))))
    (if (=c c u0)
        c
        (error 'closed-line-with-warning-begin-c))))

(define (closed-line-with-warning-end-c)
  (displayln "Closed line with a warning end coord")
  (let ((c (line-end-c (line-closed u0 ux uxyz u0))))
    (if (=c c u0)
        c
        (error 'closed-line-with-warning-end-c))))

(define (closed-line-with-warning-cs)
  (displayln "Closed line with a warning coords")
  (let ((cs (line-cs (line-closed u0 ux uxyz u0))))
    (if (andmap =c cs (list u0 ux uxyz u0))
        cs
        (error 'closed-line-with-warning-cs))))